#ifndef RDPSERVER_H
#define RDPSERVER_H

#include <filesystem>
#include <QObject>
#include <QDebug>


#include <freerdp/freerdp.h>
#include <freerdp/listener.h>
#include "rdpsession.h"

class  RdpServer: public QObject
{
    Q_OBJECT

public:
    explicit RdpServer(QObject *parent = nullptr);
    ~RdpServer();
   
    int start();
    int stop();

    quint16 port() const;
    void setPort(quint16 newPort);

    bool localOnly() const;
    void setLocalOnly(bool newLocalOnly);

    static std::filesystem::path tlsCertificate();
    static void setTlsCertificate(const std::filesystem::path &newTlsCertificate);
    static std::filesystem::path tlsCertificateKey();
    static void setTlsCertificateKey(const std::filesystem::path &newTlsCertificateKey);

    freerdp_listener* instance() const;
    
private:
    int initialize();
    int destroy();
    void server_mainloop();

    WSADATA m_wsaData;
	freerdp_listener* m_instance = nullptr;
	char* m_file;
	char m_name[MAX_PATH];


    static std::filesystem::path m_tlsCertificate;
    static std::filesystem::path m_tlsCertificateKey;
    quint16 m_port = 3389;
    bool m_localOnly = false;
};

#endif